const Mock = require('mockjs');
const getQuestionList = require('./data/getQuestionList');
const getComponentList = require('./data/getComponentList');
const Random = Mock.Random;
module.exports= [
    {
        url:'/api/question/:id',
        method:'get',
        response() {
            return {
                errno: 0,
                data: {
                    id: Random.id(),
                    title: Random.ctitle(),
                    desc: "问卷描述",
                    js: '',
                    css: '',
                    isPublished: true,
                    isDeleted: false,
                    componentList: getComponentList(),
                },
            }
        }
    },
    {
        url:'/api/question',
        method:'post',
        response() {
            return {
                errno: 0,
                data: {
                    id: Random.id(),
                },
            }
        }
    },
     {
        url:'/api/question',
        method:'get',
        response(ctx) {
            console.log(ctx.query);
            const {url, query={}} = ctx;
            const isStar = url.indexOf('isStar') >= 0;
            const isDeleted = url.indexOf('isDeleted') >= 0;
            const page = parseInt(query.page) || 1
            const pageSize = parseInt(query.pageSize) || 10
            console.log(page, pageSize);
            return {
                errno: 0,
                data: {
                    list: getQuestionList({len:pageSize,isStar,isDeleted}),
                    total: 100
                },
            }
        }
    },
    {
        url:'/api/question/:id',
        method:'patch',
        response() {
            return {
                errno: 0,
            }
        }
    },
    {
        url:'/api/question/duplicate/:id',
        method:'post',
        response() {
            return {
                errno: 0,
                data: { 
                    id: Random.id(),
                }
            }
        }
    },
    {
        url:'/api/question',
        method:'delete',
        response() {
            return {
                errno: 0,
            }
        }
    },

];